package com.order.controller.admin;

import com.order.dto.SetmealDTO;
import com.order.dto.SetmealPageQueryDTO;
import com.order.entity.Dish;
import com.order.mapper.DishMapper;
import com.order.mapper.SetmealMapper;
import com.order.result.PageResult;
import com.order.result.Result;
import com.order.service.SetmealService;
import com.order.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "餐品相关接口")
@Slf4j

public class SetmealController {
    @Autowired
    private DishMapper dishMapper;


    @Autowired
    private SetmealService setmealService;
    @PostMapping
    @ApiOperation("新增套餐接口")
    public Result createSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.createSetmeal(setmealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult=setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping
    @ApiOperation("删除套餐")
    public Result delete(@RequestParam List<Long> ids){
        setmealService.deleteBatch(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id){
        SetmealVO setmealVO=new SetmealVO();
        setmealVO=setmealService.getByIdDish(id);
        return Result.success(setmealVO);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return  Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("根据状态修改套餐起售停售")
    public Result status(@PathVariable Integer status,Long id){
        setmealService.setStatus(status,id);
        return Result.success();
    }
}
